<?php
class Func_Session{
	
	/**
	 * starts a session, or continues an existing one
	 * 
	 */
	public static function start(){
		
		session_start();
	}
	
	public static function destroy(){
		
		self::start();
		unset($_SESSION['username']);
		
		session_destroy();
	}

	/**
	 * sets the session id to the specified id
	 * 
	 * @param $id
	 */
	public static function setId($id){
			
		Validate::notNull($id);

		if(defined('SID')){
			throw new Exception("Session already exists, session id must be set before session started.");
		}
		
		session_id($id);
	}
	
	/**
	 * get the current session id
	 */
	public static function getId(){
		return session_id();
	}
	
	/**
	 * Adds a value to the current session under the given
	 * identifier.
	 * 
	 * @param $identifier
	 * @param $value
	 */
	public static function addToSession($identifier, $value){
		
		if(!defined('SID')){
			throw new Exception("Attempting to add to a session when no session exists.");
		}
		
		self::start();
		$_SESSION[$identifier] = $value;
	}
	
	public static function getSessionValue($identifier){
		
		self::start();
		
		if(!isset($_SESSION[$identifier])){
			return null;
		}
		
		return $_SESSION[$identifier];
	}
}
?>